﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security;

namespace ST.Torch.WebApi.Core.Entities.System
{
	public enum MenuTypeEnum
	{
		/// <summary>
		/// 菜单
		/// </summary>
		Menu,
		/// <summary>
		/// 页面
		/// </summary>
		Page,
		/// <summary>
		/// 按钮
		/// </summary>
		Button
	}
	public class SYSMenu : SoftDeleteBaseEntity, IEntityTypeBuilder<SYSMenu>
	{
		
		/// <summary>
		/// 菜单名称
		/// </summary>
		[MaxLength(100)]
		public string Title { get; set; }
		/// <summary>
		/// 图标
		/// </summary>
		[MaxLength(100)]
		public string Icon { get; set; }

		/// <summary>
		/// 菜单路由地址
		/// </summary>
		[MaxLength(500)]
		public string Href { get; set; }
		/// <summary>
		/// 打开方式 _component
		/// </summary>
		[MaxLength(500)]
		public string OpenType { get; set; }

		/// <summary>
		///  0 菜单 1 页面 2按钮
		/// </summary>
		public MenuTypeEnum Type { get; set; }

		/// <summary>
		/// 是否隐藏
		/// </summary>
		public bool IsHide { get; set; }
		/// <summary>
		/// 上级id, Guid.Empty是顶级
		/// </summary>
		public Guid ParentId { get; set; }
		/// <summary>
		/// 节点语义ID  顶级父Id +.+级父Id+.+...+自己id 用与like 查询
		/// </summary>
		[Column(TypeName = "varchar(1000)")]
		public string CascadeId { get; set; }

		/// <summary>
		/// 权限标识
		/// </summary>
		[Column(TypeName = "varchar(100)")]
        public string PermissionId { get; set; }

		/// <summary>
		/// 排序
		/// </summary>
        public int Sort { get; set; }



        //public virtual List<SYSRoleMenu> RoleMenus { get; set; }
        public virtual List<SYSRole> Roles { get; set; }

        public void Configure(EntityTypeBuilder<SYSMenu> entityBuilder, DbContext dbContext, Type dbContextLocator)
		{
			entityBuilder.HasKey(u => u.Id);
			entityBuilder.HasQueryFilter(u => !u.IsDeleted);
            entityBuilder.HasMany(u => u.Roles).WithMany(u => u.Menus).UsingEntity(e => e.ToTable("SYSRoleMenu"));

        }
    }

}
